package cn.com.coldg.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import cn.com.coldg.bean.UserInfo;
import cn.com.coldg.bean.UserTeam;
import cn.com.coldg.factory.DAOFactory;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{	
		
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List <UserInfo> userList= new ArrayList<UserInfo>();
	private UserInfo user;
	private String userName;
	private int id;
	
	public String Query(){
		userList=DAOFactory.getUserInfoDAOInstance().findAll();
		return SUCCESS;
	}
	
	public String findByName(){
		userList=DAOFactory.getUserInfoDAOInstance().findByName(userName);
		return SUCCESS;
	}
	
	public String adduser()throws Exception{
		try {
			user.setInseterTime(new Timestamp(System.currentTimeMillis()));
			DAOFactory.getUserInfoDAOInstance().add(user);
		//	DAOFactory.getUserTeamDAOInstance().add(team);
			
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}
	
	
	public String findById(){
		user = DAOFactory.getUserInfoDAOInstance().findById(id);
		return SUCCESS;
	}
	public String modify(){
		DAOFactory.getUserInfoDAOInstance().update(user);
		return SUCCESS;
	}
	
	public String delete(){
		boolean ret = DAOFactory.getUserInfoDAOInstance().delete(id);
		if(ret){
			return SUCCESS;
		}else{
			return ERROR;
		}	
	}
	
	
	public List<UserInfo> getUserList() {
		return userList;
	}
	public void setUserList(List<UserInfo> userList) {
		this.userList = userList;
	}

	public UserInfo getUser() {
		return user;
	}

	public void setUser(UserInfo user) {
		this.user = user;
	}

	
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
		
	
}
